#!/usr/bin/env python
#-*- coding: utf_8 -*-
import SimpleHTTPServer
import SocketServer
from threading import Thread

class Server(Thread):
    '''
    Esta class cria um processo a correr simpleHttpServer na porta selecionada
    '''
    def __init__(self,PORT):       
        Thread.__init__(self)
        self.PORT=PORT
        

        
    def run(self):
        try:
            Handler = SimpleHTTPServer.SimpleHTTPRequestHandler        
            self.httpd = SocketServer.TCPServer(("", self.PORT), Handler)        
            print "serving at port", self.PORT
            self.httpd.serve_forever()
        except: 
            pass
    '''
    Faz shutdown ao servidor para libertar a porta
    '''
    def stop(self):
        self.httpd.shutdown()
        self.httpd.close_request()
